package edu.neusoft.yuejian_09.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.List;

import edu.neusoft.yuejian_09.R;
import edu.neusoft.yuejian_09.bean.Contest;
import it.sephiroth.android.library.picasso.Picasso;

import static edu.neusoft.yuejian_09.base.Constant.POST_PHOTO_URL;


/**
 * Created by Administrator on 2017/10/25.
 */

public class MyCollectMatchListAdapter  extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContex;
    private List mDataList;
    private ViewHolder viewHolder;
    private LayoutInflater mLayoutInflater;

    public MyCollectMatchListAdapter(Context mContext, List mDataList) {
        this.mContex = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_my_collect, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Contest entity = (Contest) mDataList.get(position);
        if (null == entity)
            return;

        ViewHolder viewHolder = (ViewHolder) holder;

        viewHolder.name.setText(entity.getContest_name());

        String t_pic = POST_PHOTO_URL + entity.getContest_pic();
        //System.out.print("pic");
        if (!t_pic.equals("")) {
            Picasso.with(mContex).load(t_pic).into(viewHolder.pic);
        }

    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView pic;
        TextView name;

        public ViewHolder(View itemView) {
            super(itemView);
            name = (TextView) itemView.findViewById(R.id.name);
            pic = (ImageView) itemView.findViewById(R.id.pic);


        }
    }
}